<template>
  <div>
    <el-container>
        <el-header class="homeHeader">
            <div class="title">人事管理系统</div>
            <div>
                <el-button icon="el-icon-chat-dot-round" type="text" style="margin-right: 10px;color: #000000" size="normal" @click="goChat"></el-button>
                <el-dropdown class="userInfo" @command="commandHeader">
            <span class="el-dropdown-link">
                {{user.name}}<i> <img :src="user.userface"></i>
            </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
                        <el-dropdown-item command="setting">设置</el-dropdown-item>
                        <el-dropdown-item command="logout" divided>注销登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </el-header>
        <el-container>
            <el-aside width="200px" style="overflow: hidden">
                <el-menu router unique-opened>
                    <el-submenu :index="index+''" v-for="(item,index) in routes" v-if="!item.hidden":key="index">
                        <template slot="title">
                            <i style="color: rgb(99, 208, 208);margin-right: 5px" :class="item.iconCls"></i>
                            <span>{{item.name}}</span>
                        </template>
                        <el-menu-item :index="child.path" v-for="(child,indexj) in item.children" :key="indexj">
                            {{ child.name }}
                        </el-menu-item>
                    </el-submenu>
                    </el-menu>
            </el-aside>
            <el-main style="margin-top: 10px;padding: 0px">
                <el-breadcrumb separator=">" v-show="this.$router.currentRoute.path!=='/home'" style="margin-left: 10px">
                    <el-breadcrumb-item :to="{ path: '/' }" >首页</el-breadcrumb-item>
                    <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
                </el-breadcrumb>
                <div v-show="this.$router.currentRoute.path === '/home'">
                    <div class="mainWelcome" >
                        欢迎来到人事管理系统！
                    </div>
                    <div >
                        <el-carousel height="500px" style="width: 800px;margin-left: 210px;border-radius: 20px;margin-top: 10px">
                            <el-carousel-item v-for="item in imgs" :key="item">
                                <img :src="item" alt="">
                            </el-carousel-item>
                        </el-carousel>
                    </div>
                </div>
                <router-view class="routerView"/>
            </el-main>
        </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
    name:'Home',
    data() {
        return {
           // user: JSON.parse(window.sessionStorage.getItem("user"))
            imgs: [
                "https://ts1.cn.mm.bing.net/th/id/R-C.dbdaf4e4041b9e2ba49b633333e600cd?rik=Th09lDaRKQMYkg&riu=http%3a%2f%2flserp.com%2ffileRoot%2fEditor%2fupload%2fimage%2f20201102%2f6373993667200976694128220.jpg&ehk=3STzPp1NUs7oZ%2bwvrQEx1b0NrcdEV0eDr0hXA%2ftmfXE%3d&risl=&pid=ImgRaw&r=0",
                "https://ts1.cn.mm.bing.net/th/id/R-C.65a96d2cb0f30f4648973a78059505e4?rik=tkUiFkk%2fKRvL5g&riu=http%3a%2f%2flserp.com%2ffileRoot%2fEditor%2fupload%2fimage%2f20201102%2f6373993666213374073678019.jpg&ehk=wyJGjC89Fte3tLTBvmdo8L8t%2bBkjRJccGmRapyJZ%2fJw%3d&risl=&pid=ImgRaw&r=0",
                "https://ts1.cn.mm.bing.net/th/id/R-C.85a415f30467bb5e1e59bca733184020?rik=cfBuKzUbDSPDog&riu=http%3a%2f%2fwww.daytime.net.cn%2fUploads%2fPicture%2f2021-03-15%2f604ed15b812b1_93.jpg&ehk=zUMvwHm52avB7IHR9vXZpAo7s5XN8YX%2bfBRoF9jV1vA%3d&risl=&pid=ImgRaw&r=0",
                "https://ts1.cn.mm.bing.net/th/id/R-C.fc3300160bf0ab6995766414cf7f74ad?rik=U5JxjVfebu8lOg&riu=http%3a%2f%2fwww.daytime.net.cn%2fUploads%2fPicture%2f2021-03-15%2f604ed15ca4e37_99.jpg&ehk=4zOJSYZj538hyKXb2YDL8hLY7w19dKI%2bYEAOtg3zdJ8%3d&risl=&pid=ImgRaw&r=0"
            ]
        }
    },
    computed:{
        routes(){
            return this.$store.state.routes;
        },
        user (){
            return this.$store.state.currentHr;
        }
    },
    methods:{
        goChat(){
            this.$router.push("/chat");
        },
        commandHeader(cmd) {
            if(cmd === 'logout'){
                this.$confirm('此操作将退出登录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                    }).then(() => {
                        this.getRequest('/logout');
                        window.sessionStorage.removeItem('user');
                        this.$store.commit('initRoutes',[]);
                        this.$router.replace("/");
                    }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消操作'
                    });          
                });
            }
            if(cmd == 'userInfo'){
                this.$router.push("/hrinfo");
            }
        }
    }
}
</script>

<style>
    .routerView {
        margin-top: 10px;
    }
    .homeHeader{
        background-color: rgb(99, 208, 208);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0px 15px;
        box-sizing: border-box;
    }
    .homeHeader .title{
        font-size: 35px;
        font-family: 华文行楷;
        color: #fff;
    }
    .homeHeader .userInfo{
        cursor:pointer;
    }
    .el-dropdown-link {
        display: flex;
        align-items: center;
    }
    .el-dropdown-link img{
        width: 48px;
        height: 48px;
        border-radius: 24px;
        margin-left: 15px;
    }
    .mainWelcome {
        text-align: center;
        font-size: 35px;
        font-family: 华文行楷;
        color: rgb(99, 208, 208);
        margin-top: 30px;
    }

</style>